package com.cutefool.zero.code.admin.dbms.web;

import com.cutefool.core.res.Response;
import com.cutefool.rds.meta.libs.ColumnLibs;
import com.cutefool.zero.code.admin.consts.Constants;
import com.cutefool.zero.code.admin.dbms.service.DbmsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 相关接口
 *
 * @author : 271007729@qq.com
 */
@RestController
@RequestMapping(Constants.API_PREFIX)
public class DdmsMetaController {

    @Resource
    private DbmsService dbmsService;

    /**
     * 查询（列表）
     *
     * @param id id
     * @return Response<List < String>>
     **/
    @GetMapping("/list/{id}/dbms-tables")
    public Response<List<String>> list(@PathVariable Long id) {
        List<String> strings = dbmsService.listTables(id);
        return Response.ok(strings);
    }

    /**
     * 查询字段（列表）
     *
     * @param id id
     * @return Response<List < String>>
     **/
    @GetMapping("/list/{id}/{table}/dbms-columns")
    public Response<List<ColumnLibs>> list(@PathVariable Long id, @PathVariable String table) {
        List<ColumnLibs> strings = dbmsService.listColumn(id, table);
        return Response.ok(strings);
    }
}
